
$(()=>{
    let urlParamIndex=location.href.indexOf('/admin');
    let urlParam=location.href.substring(urlParamIndex+7);
    // console.log(urlParam);
    // 先给侧边栏各项设置对应id，利用地址对应id名添加d当前属性和样式，免去判断这以流程
    $('#'+urlParam).addClass('active');
    // 通过判断路径，确定侧边栏的展开情况
    if(urlParam=='posts'
    ||urlParam=='post-add'
    ||urlParam=='categories'
    ){
        // 修改侧边栏的展开情况
        $('#target-posts').attr("aria-expanded","true")
        .removeClass("collapsed");
        $("#menu-posts").addClass('show');
    }else if(urlParam=='slides'
    ||urlParam=='settings'
    ){
        $('#target-settings').attr("aria-expanded","true")
        .removeClass("collapsed");
        $('#menu-settings').addClass('show');
    }
    // 设置用户登录后对应昵称和头像
    $.get('/getUserNameAndImg',(res)=>{
        // console.log(res);
        if(res.code===200){
            $('.profile>.name').text(res.data.nickname);
            $('.profile>.avatar').attr('src',res.data.avatar);  
        }else{
            alert('您的网络较差，读取头像失败，请重试');
        }
    })

})